package com.src.notebookofcy;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.baidu.mobstat.SendStrategyEnum;
import com.baidu.mobstat.StatService;
import java.io.File;

public class EditActivity extends Activity
{
  public static final String CONTENT = "content";
  public static final String EDIT_CONTENT = "edit_content";
  public static final String EDIT_TITLE = "edit_title";
  public static final String TITLE = "title";
  private String Content = "";
  private Button btn_save;
  public String content_first = "";
  private EditText edt_content;
  private EditText edt_title;
  private File file;
  public FileTools fileTools;
  byte intentState;
  boolean isRunning;
  public boolean isSave;
  private Context mContext;
  public View.OnClickListener onClickListener = new View.OnClickListener()
  {
    public void onClick(View paramView)
    {
      switch (paramView.getId())
      {
      default:
        return;
      case 2131165196:
      }
      EditActivity.this.saveFile();
      EditActivity.this.isSave = true;
    }
  };
  public DialogInterface.OnClickListener onDialogClickListener = new DialogInterface.OnClickListener()
  {
    public void onClick(DialogInterface paramDialogInterface, int paramInt)
    {
      switch (paramInt)
      {
      default:
        return;
      case -1:
      }
      EditActivity.this.saveFile();
      EditActivity.this.startActivity(new Intent(EditActivity.this, MainActivity.class));
    }
  };
  SharedPreferences sharedPreferences;
  public TextWatcher textWatcher = new TextWatcher()
  {
    public void afterTextChanged(Editable paramEditable)
    {
      EditActivity.this.saveDataByShared();
      if (EditActivity.this.intentState != 1)
        return;
      EditActivity.this.saveDataEdit();
    }

    public void beforeTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3)
    {
    }

    public void onTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3)
    {
    }
  };
  private String title = "";
  public String title_first = "";

  public void dataInit()
  {
    this.mContext = this;
    this.isRunning = true;
    this.fileTools = new FileTools();
    SimpleClass.getSimpleClass();
    this.file = SimpleClass.getFile();
    this.sharedPreferences = getSharedPreferences("SharedPreferences", 0);
  }

  public void getIntentData()
  {
    this.intentState = getIntent().getByteExtra("STATE", 0);
    if (this.intentState == 1)
    {
      this.edt_title.setText(this.file.getName().substring(0, -4 + this.file.getName().length()));
      this.edt_content.setText(FileTools.openText(this.file));
      this.title_first = this.edt_title.getText().toString();
      this.content_first = this.edt_content.getText().toString();
      return;
    }
    this.edt_title.setText("");
    this.edt_content.setText("");
  }

  public String getNoteContent()
  {
    return this.edt_content.getText().toString();
  }

  public String getNoteTitle()
  {
    return this.edt_title.getText().toString();
  }

  public boolean isUpdata()
  {
    return (!this.title_first.equals(getNoteTitle())) || (!this.content_first.equals(getNoteContent()));
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903042);
    dataInit();
    viewInit();
    sdCardState();
    getIntentData();
    StatService.setSendLogStrategy(this, SendStrategyEnum.APP_START, 1, false);
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if ((paramInt == 4) && (!this.isSave) && (isUpdata()))
    {
      new AlertDialog.Builder(this.mContext).setTitle("提示").setMessage("内容尚未保存!是否保存？").setPositiveButton("保存", this.onDialogClickListener).setNegativeButton("取消", this.onDialogClickListener).create().show();
      return true;
    }
    return super.onKeyDown(paramInt, paramKeyEvent);
  }

  protected void onPause()
  {
    super.onPause();
    StatService.onPause(this);
    saveDataByShared();
  }

  protected void onResume()
  {
    super.onResume();
    StatService.onResume(this);
    this.isSave = false;
  }

  public void readDataByShared()
  {
    String str1 = this.sharedPreferences.getString("title", "");
    String str2 = this.sharedPreferences.getString("content", "");
    this.edt_title.setText(str1);
    this.edt_content.setText(str2);
  }

  public void readDataEdit()
  {
    String str1 = this.sharedPreferences.getString("edit_title", "");
    String str2 = this.sharedPreferences.getString("edit_content", "");
    String str3 = SimpleClass.getFile().getName();
    str3.substring(0, -4 + str3.length());
    this.edt_title.setText(str1);
    this.edt_content.setText(str2);
  }

  public void saveDataByShared()
  {
    SharedPreferences.Editor localEditor = this.sharedPreferences.edit();
    localEditor.putString("title", getNoteTitle());
    localEditor.putString("content", getNoteContent());
    localEditor.commit();
  }

  public void saveDataEdit()
  {
    SharedPreferences.Editor localEditor = this.sharedPreferences.edit();
    localEditor.putString("edit_title", getNoteTitle());
    localEditor.putString("edit_content", getNoteContent());
    localEditor.commit();
  }

  public void saveFile()
  {
    this.title = getNoteTitle();
    this.Content = getNoteContent();
    if (this.title.equals(""))
      Toast.makeText(this.mContext, "请输入标题", 0).show();
    do
    {
      return;
      this.fileTools.saveFile(this.Content, this.title);
      Toast.makeText(this.mContext, "保存成功!", 0).show();
    }
    while ((this.intentState != 1) || (this.title.equals(this.file.getName().substring(0, -4 + this.file.getName().length()))));
    FileTools.deleteFile(this.file);
  }

  public void sdCardState()
  {
    if (this.fileTools.getSdcardState())
      return;
    Toast.makeText(this.mContext, "SD异常!", 0).show();
  }

  public void viewInit()
  {
    this.edt_title = ((EditText)findViewById(2131165194));
    this.edt_content = ((EditText)findViewById(2131165195));
    this.btn_save = ((Button)findViewById(2131165196));
    this.btn_save.setOnClickListener(this.onClickListener);
    this.edt_content.addTextChangedListener(this.textWatcher);
  }
}

/* Location:           C:\Users\god\Desktop\liunianjishiben_V1.1_mumayi_3745b_dex2jar.jar
 * Qualified Name:     com.src.notebookofcy.EditActivity
 * JD-Core Version:    0.5.4
 */